#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

int main()
{
	int fd = 0;
	char buf[1024] = {0};
	char dest[1024] = {0};
	int ret = 0;

	fd = open("./new.txt",O_RDWR | O_CREAT | O_APPEND,0640);
	if(fd == -1)
	{
		perror("open");
		exit(-1);
	}

	printf("please input a string:\n");
	scanf("%s",buf);

	ret = write(fd,buf,strlen(buf));
	if(ret == -1)
	{
		perror("write");
		exit(-1);
	}

	lseek(fd,0,SEEK_SET);
	ret = read(fd,dest,1023);
	if(ret == -1)
	{
		perror("read");
		exit(-1);
	}

	printf("dest is %s\n",dest);

	close(fd);

	return 0;
}
